package com.lkd.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.lkd.dto.TaskDTO;
import com.lkd.dto.TaskTypeDTO;
import com.lkd.entity.Task;
import com.lkd.entity.TaskStatusType;
import com.lkd.entity.TaskType;
import com.lkd.result.TableInfo;
import com.lkd.service.TaskService;
import com.lkd.vo.TaskReportVO;
import com.lkd.vo.TaskVO;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @Author: Z.lx
 * @Date: 2025/8/23 16:20
 * @Description:
 **/
@RequestMapping("/api/task-service/task")
@RestController
@Slf4j
@AllArgsConstructor
public class TaskController {
    private final TaskService taskService;

    /**
    * @Description 新增工单
    * @Param [task]
    * @Date 2025/8/23 16:26
    **/
    @PostMapping("/create")
    public boolean create(@RequestBody Task  task){
        log.info("新增工单");
        return taskService.save(task);
    }
    /**
    * @Description 取消工单
    * @Param [taskId]
    * @Date 2025/8/23 16:26
    **/
    @PostMapping("/cancel/{taskId}")
    public boolean cancel(@PathVariable Long taskId,@RequestBody TaskDTO taskDTO){
        log.info("取消工单");
        return taskService.cancel(taskId,taskDTO);
    }
    /**
    * @Description 工单搜索
    * @Param [taskDTO]
    * @Date 2025/8/23 16:26
    **/
    @GetMapping("/search")
    public TableInfo<TaskVO> list(TaskDTO taskDTO){
        log.info("工单搜索{}",taskDTO);
        return taskService.search(taskDTO);
    }
    /**
    * @Description 工单详情
    * @Param [taskId]
    * @Date 2025/8/23 16:26
    **/
    @GetMapping("/allTaskStatus")
    public List<TaskStatusType> getAllStatus(){
        log.info("工单详情");
        return taskService.getAllStatus();
    }

    /**
    * @Description 工单统计
    * @Param [time]
    * @Date 2025/8/27 14:24
    **/
    @GetMapping("/taskReportInfo/{start}/{end}")
    public List<TaskReportVO> getAllType(@PathVariable("start") String start,
                              @PathVariable("end") String end){
        return taskService.getTaskReportInfo(start,end);
    }

    @GetMapping("/collectReport/{start}/{end}")
    public List<TaskReportVO> collectReport(@PathVariable("start") String start,
                                                @PathVariable("end") String end){
        return taskService.getTaskReportInfo(start,end);
    }

}
